package com.minsus.secretmailbox;

import java.io.IOException;
import java.net.URLDecoder;
import java.util.Vector;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;

public class HttpClientPost {

	private HttpClient mHttpClient;

	// Constructor
	public HttpClientPost() {
		mHttpClient = new DefaultHttpClient();
	}

	public String httpSetRegstrationId(String url, String uid, String rid,
			String model, String version) throws ClientProtocolException,
			IOException {
		String result = "";
		HttpPost request = new HttpPost(url);
		HttpEntity entity;
		HttpResponse response;

		Vector<NameValuePair> nameValue = new Vector<NameValuePair>();

		nameValue.add(new BasicNameValuePair("uid", uid));
		nameValue.add(new BasicNameValuePair("rid", rid));
		nameValue.add(new BasicNameValuePair("model", model));
		nameValue.add(new BasicNameValuePair("version", version));

		// Post로 데이터를 보내는 방식을 UTF-8로 설정
		entity = new UrlEncodedFormEntity(nameValue, HTTP.UTF_8);

		request.setEntity(entity);
		response = mHttpClient.execute(request);
		result = EntityUtils.toString(response.getEntity());

		result = URLDecoder.decode(result, HTTP.UTF_8);
		
		return result;
	}
} // end of class HttpClientPost
